package android.demo.engine.tasks.hardcoded;

import android.content.Context;
import android.content.Intent;
import android.demo.engine.ProcessStateManager;
import android.demo.engine.tasks.ActivityTask;
import android.demo.engine.tasks.TaskFactory;
import android.demo.engine.visitor.TaskVisitor;
import android.demo.library.LoanBookActivity;
import android.demo.library.ReturnBookActivity;
import android.demo.library.model.Library;
import android.widget.Toast;

public class HardCodedActivityTask extends ActivityTask{
	
	public HardCodedActivityTask(int id) {
		super(id);
	}

	public Intent prepareIntent(Context context, ProcessStateManager processState){
		int id= getId();
		switch(id){
		case TaskFactory.LOAN_TASK :
			return prepareIntentForLoan(context,processState);
		case TaskFactory.RETURN_TASK:
			return prepareIntentForReturn(context,processState);
		default :
			return null;
		}
	}
	public void manageResult(Intent intent, ProcessStateManager processState){
		int id= getId();
		switch(id){
		case TaskFactory.LOAN_TASK :
			manageDataFromLoan(intent,processState);
			break;
		case TaskFactory.RETURN_TASK:
			manageDataFromReturn(intent,processState);
			break;
		}
		finish();
	}
	
	private Intent prepareIntentForReturn(Context context,ProcessStateManager currentState) {
		Intent intent= new Intent(context,ReturnBookActivity.class);
		return intent;
	}

	private Intent prepareIntentForLoan(Context context,ProcessStateManager currentState) {
		Intent intent= new Intent(context,LoanBookActivity.class);
		return intent;
	}


	private void manageDataFromReturn(Intent intent, ProcessStateManager currentState) {
		
	}

	private void manageDataFromLoan(Intent intent, ProcessStateManager currentState) {
		long bookId= intent.getExtras().getLong(Library.KEY_ID);
		currentState.putLong(Library.KEY_ID, bookId);
	}

	@Override
	public void accept(TaskVisitor visitor) {
				visitor.visit(this);
	}
	
	@Override
	public boolean hasResult() {
		return true;
	}

}
